home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gdevsnfb.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  3.3 KB  |  118 lines

  1. /* Copyright (C) 1989, 1990, 1991, 1996, 1998 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gdevsnfb.c,v 1.2 2000/09/19 19:00:22 lpd Exp $*/
  20. /* Sony News frame buffer driver for GhostScript */
  21. #include "gdevprn.h"
  22. #define prn_dev ((gx_device_printer *)dev) /* needed in 5.31 et seq */
  23. /*#include <sys/types.h> problems with ushort! */
  24. typedef    char *    caddr_t;
  25. typedef    long    off_t;
  26. #include <sys/uio.h>
  27. #include <newsiop/framebuf.h>
  28.  
  29. /* The device descriptor */
  30. private dev_proc_open_device(sonyfb_open);
  31. private dev_proc_output_page(sonyfb_output_page);
  32. private dev_proc_close_device(sonyfb_close);
  33. private gx_device_procs sonyfb_procs =
  34.   prn_procs(sonyfb_open, sonyfb_output_page, sonyfb_close);
  35. gx_device_printer far_data gs_sonyfb_device =
  36.   prn_device(sonyfb_procs, "sonyfb",
  37.     102.4,                /* width_10ths */
  38.     103.2,                /* height_10ths */
  39.     100,                /* x_dpi */
  40.     100,                /* y_dpi */
  41.     0,0,0,0,            /* margins */
  42.     1, 0);
  43.  
  44. private int fb_file = -1;
  45. sPrimRect prect;
  46.  
  47. private int
  48. sonyfb_open(gx_device *dev)
  49. {
  50.   sScrType stype;
  51.  
  52.   if(fb_file < 0)
  53.     if((fb_file = open("/dev/fb", 2)) < 0)
  54.       perror("open failed");
  55.     else
  56.       if(ioctl(fb_file, FBIOCGETSCRTYPE, &stype) < 0)
  57.     perror("ioctl failed");
  58.       else
  59.     prect.rect = stype.visiblerect;
  60.  
  61.   return gdev_prn_open(dev);
  62. }
  63.  
  64. private int
  65. sonyfb_close(gx_device *dev)
  66. {
  67.   if(fb_file >= 0)
  68.     {
  69.       close(fb_file);
  70.       fb_file = -1;
  71.     }
  72.   return gdev_prn_close(dev);
  73. }
  74.  
  75. #define FRAME_WIDTH    1024
  76.  
  77. /* Send the page to the printer. */
  78. private int
  79. sonyfb_output_page(gx_device *dev, int num_copies, int flush)
  80. {
  81.   int l, i, byte_width, height;
  82.   unsigned char *bm, *fbs, *fb;
  83.  
  84.   byte_width = (dev->width + 7) / 8;
  85.   height = dev->height;
  86.   bm     = (typeof(bm))prn_dev->mem.base;
  87.  
  88.   prect.refPoint.x = 0;
  89.   prect.refPoint.y = 0;
  90.   prect.ptnRect = prect.rect;
  91.   
  92.   prect.ptnBM.type  = BM_MEM;
  93.   prect.ptnBM.depth = 1;
  94.   prect.ptnBM.width = (byte_width + 1) / 2;
  95.   prect.ptnBM.rect.origin.x = 0;
  96.   prect.ptnBM.rect.origin.y = 0;
  97.   prect.ptnBM.rect.extent.x = byte_width * 8; /* width in 16bit words */
  98.   prect.ptnBM.rect.extent.y = height;
  99.   prect.ptnBM.base = (typeof(prect.ptnBM.base))bm;
  100.   
  101.   prect.fore_color = 1;
  102.   prect.aux_color = 0;
  103.   prect.planemask = FB_PLANEALL;
  104.   prect.transp = 0;
  105.   prect.func = BF_S;
  106.   prect.clip = prect.rect;
  107.   prect.drawBM.type  = BM_FB;
  108.   prect.drawBM.depth = 1;
  109.   prect.drawBM.width = (prect.rect.extent.x + 15) / 16;
  110.   prect.drawBM.rect = prect.rect;
  111.   prect.drawBM.base = 0;
  112.   
  113.   if(ioctl(fb_file, FBIOCRECTANGLE, &prect) < 0)
  114.     perror("rect ioctl failed");
  115.  
  116.   return gx_finish_output_page(dev, num_copies, flush);
  117. }
  118.